﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus.Partner.Region
{
    public partial class regioniForma : Form
    {
        private int idRegiona;
        public regioniForma()
        {
            InitializeComponent();
        }

        Arthus.Region regionObjekat = null;

        private void regioniForma_Load(object sender, EventArgs e)
        {
            regionObjekat = new Arthus.Region();
            regionObjekat.PopuniListBox(listBoxRegioni);
            regionObjekat.PopuniKontroleNaOsnovuIdRegiona(idRegiona, textBoxOznaka, textBoxNaziv, textBoxOpis);
            listBoxRegioni.SelectedIndex = 0;
        }

        private void regioniForma_Activated(object sender, EventArgs e)
        {
            regionObjekat = new Arthus.Region();
            regionObjekat.PopuniListBox(listBoxRegioni);
            regionObjekat.PopuniKontroleNaOsnovuIdRegiona(idRegiona, textBoxOznaka, textBoxNaziv, textBoxOpis);
            idRegiona = Convert.ToInt32(listBoxRegioni.SelectedItem.ToString().Split('.')[0]);
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TABKaoENTER(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                SelectNextControl(ActiveControl, true, true, true, true);
            }
        }
        private void textBoxOznaka_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNaziv_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxOpis_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }

        private void VratiSveNaPocetak()
        {
            textBoxOznaka.Text = "";
            textBoxNaziv.Text = "";
            textBoxOpis.Text = "";
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            regionObjekat = new Arthus.Region();
            regionObjekat.DodajRegion(textBoxOznaka, textBoxNaziv, textBoxOpis);
            VratiSveNaPocetak();
            textBoxOznaka.Focus();
        }

        private void listBoxRegioni_SelectedIndexChanged(object sender, EventArgs e)
        {
            idRegiona = Convert.ToInt32(listBoxRegioni.SelectedItem.ToString().Split('.')[0]);
            regionObjekat = new Arthus.Region();
            regionObjekat.PopuniKontroleNaOsnovuIdRegiona(idRegiona, textBoxOznaka, textBoxNaziv, textBoxOpis);
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            regionObjekat = new Arthus.Region();
            regionObjekat.IzmeniRegion(idRegiona, textBoxOznaka, textBoxNaziv, textBoxOpis);
        }

        private void buttonObrisi_Click(object sender, EventArgs e)
        {
            regionObjekat = new Arthus.Region();
            regionObjekat.ObrisiRegion(idRegiona);
        }

    }
}
